home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / ms_dos / cd_lib / src / cdr_seek.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-08  |  1.2 KB  |  51 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4. #include "define.h"
  5.  
  6. #ifdef DEBUG
  7. main(int argc, char *argv[])
  8. {
  9.     long int sec;
  10.     
  11.     if (argc > 1) {
  12.         printf("input is %s\n", argv[1]);
  13.         sec = atol(argv[1]);
  14.         printf("Seek %lx sector\n", sec);
  15.         printf("return is %x\n", cdr_seek(0, sec));
  16.     }
  17. }
  18. #endif
  19.  
  20. /* 指定位置へのシーク(論理セクタ指定) */
  21. /*
  22.  * decice_no:   device number (Towns CD-ROM -> 0)
  23.  * sector_number: 論理セクター番号
  24.  * return: 0 -> 正常終了, 0以外 -> エラー
  25.  */
  26. int cdr_seek(int device_no, long int sector_number)
  27. {
  28.     union REGS reg;
  29.     
  30.     reg.h.ah = 0x04;
  31.     reg.h.al = (0xC0 | (u_char) device_no);
  32.     reg.x.cx = 0x0000;
  33.     reg.h.cl = (u_char) ((u_long) sector_number) >> 16;    /* High */
  34.     reg.x.dx = (u_int) (sector_number & 0x00ffff); /* Low */
  35. #ifdef DEBUG
  36.     printf("sector number: High is %x, Low is %x\n", reg.h.cl, reg.x.dx);
  37. #endif
  38.     int86(0x93, ®, ®);
  39.     
  40.     if (reg.h.ah == 0) {
  41.         return 0;
  42.     } else if (reg.h.ah == 0x02) {  /* device number error */
  43.         return DEVERR;
  44.     } else if (reg.h.ah == 0x10) {    /* cd-da plaing */
  45.         return DEVPLY;          
  46.     } else {                        /* (reg.h.ah == 0x80) hard ware error */
  47.         return reg.x.cx;
  48.     }
  49. }
  50.  
  51.